Ext.define('Emp.controller.RoleController', {
    extend: 'Emp.controller.BaseController',

    models: ['Role'],
    views: ['role.List', 'role.Edit', 'role.UserConfig', 'role.PermissionConfig'],
    refs: [
        {ref: 'roleList', selector: 'rolelist'},
        {ref: 'roleEdit', selector: 'roleedit', xtype: 'roleedit', autoCreate: true},
        {ref: 'userConfig', selector: 'userconfig', xtype: 'userconfig', autoCreate: true},
        {ref: 'permissionConfig', selector: 'permissionconfig', xtype: 'permissionconfig', autoCreate: true}
    ],
    
    init: function() {
        this.control({
        	'rolelist grid': {
        		'itemdblclick': this.doModifyOnList
        	},
            'rolelist gridtoolbar button[itemId=create]': {
                'click': this.doCreateOnList
            },
            'rolelist gridtoolbar button[itemId=modify]': {
                'click': this.doModifyOnList
            },
            'rolelist gridtoolbar button[itemId=read]': {
                'click': this.doReadOnList
            },
            'rolelist gridtoolbar button[itemId=remove]': {
                'click': this.doRemoveOnList
            },
            'rolelist gridtoolbar button[itemId=userConfig]': {
                'click': this.doUserConfig
            },
            'rolelist gridtoolbar button[itemId=permissionConfig]': {
                'click': this.doPermissionConfig
            },
            'roleedit': {
                'afterrender': this.doLoadOnEdit
            },
            'roleedit button[action=save]': {
                'click': this.doSaveOnEdit
            },
            'roleedit menuitem[action=save_close]': {
                'click': this.doSaveCloseOnEdit
            },
            'roleedit button[action=create]': {
                'click': this.doCreateOnEdit
            },
            'roleedit button[action=close]': {
                'click': this.doCloseOnEdit
            }
        });
    },
    
    doUserConfig: function() {
    	var record = this.getRoleList().grid.getSelectionModel().getSelection()[0];
		if (record) {
			var id = record.get(record.idProperty);
			var edit = this.getUserConfig({roleId: id});
			this.getRoleList().add(edit);
			edit.show();
		} else {
			Ext.show.msg('提示', '请选择数据');
		}
    },
    
    doPermissionConfig: function() {
    	var record = this.getRoleList().grid.getSelectionModel().getSelection()[0];
		if (record) {
			var id = record.get(record.idProperty);
			var edit = this.getPermissionConfig({roleId: id});
			this.getRoleList().add(edit);
			edit.show();
		} else {
			Ext.show.msg('提示', '请选择数据');
		}
    }
});